package com.hebrf.sdk.dialog;

/**
 * Created by lyb on 2017/6/13.
 * Email: 1373519715@qq.com
 * Blog: https://littleiii.github.io
 */

import android.app.Activity;
import android.support.v7.app.AlertDialog;
import android.view.View;
import android.widget.TextView;

/**
 * 选择类对话框（yses or no）
 */
public class YnDialog implements BaseDialog {


    private AlertDialog mAD;
    private View mView;
    private String content;
    private TextView tvContent;
    private TextView tvYes;
    private TextView tvNo;

    private CallBack mCallBack;

    public YnDialog(Activity activity, CallBack callBack) {
        mCallBack = callBack;
        mView = View.inflate(activity, 0, null);
        mAD = new AlertDialog.Builder(activity).
                setView(mView).
                create();
        tvContent = (TextView) mView.findViewById(0);
        tvYes = (TextView) mView.findViewById(0);
        tvNo = (TextView) mView.findViewById(0);
        tvYes.setOnClickListener((view) -> {
            callBack.callYes();
            cancel();
        });
        tvNo.setOnClickListener((view) -> {
            callBack.callNo();
            cancel();
        });
    }


    @Override
    public String getContent() {
        return content;
    }

    @Override
    public void setContent(String s) {
        content = s;
        tvContent.setText(content);

    }

    @Override
    public AlertDialog getDialog() {
        return mAD;
    }

    @Override
    public void show() {
        if (mAD == null) {
            return;
        }
        mAD.show();
    }

    @Override
    public void cancel() {
        if (mAD == null) {
            return;
        }
        mAD.cancel();
    }


    public static interface CallBack {
        void callYes();

        void callNo();
    }


}
